package com.pruebas.andEngine;

import org.anddev.andengine.engine.handler.physics.PhysicsHandler;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

public class ManzanaRoja extends AnimatedSprite{ 
	private final PhysicsHandler mPhysicsHandler;
	private Float posicionActualX;
	private Float posicionActualY;
	private int camara_height = 0;
	private Boolean llegoPiso = false;
	static final int DESPLAZAMIENTOX = 10;
	static final int DESPLAZAMIENTOY = 10;
	
	public ManzanaRoja(final float pX, final float pY, final TiledTextureRegion pTextureRegion){
		super(pX, pY, pTextureRegion);
		this.mPhysicsHandler = new PhysicsHandler(this);
	    this.registerUpdateHandler(this.mPhysicsHandler);
	}

	public void setVelocityY(float velocity){
	    mPhysicsHandler.setVelocityY(velocity);
	}
	
	public boolean moveSprite(int valor){
		posicionActualX = this.getX();
		posicionActualY = this.getY();
			//le agregue 25 pixeles para que quede mas retirado del piso
			if(this.getY() + this.getHeight() + 25 <= camara_height){
				//this.setPosition(posicionActualX - DESPLAZAMIENTOX , posicionActualY + 10); // this.getX() - 10
				/*int topeY = (int) (posicionActualY + (DESPLAZAMIENTOY + valor));
				if(topeY > this.getY() + this.getHeight() + 25)
					topeY =*/ 
				this.setPosition(posicionActualX - DESPLAZAMIENTOX , posicionActualY + (DESPLAZAMIENTOY + valor)); // this.getX() - 10
				return true;
			}else{
				
	            this.setPosition(posicionActualX - DESPLAZAMIENTOX, posicionActualY);  //posicionActualX - 10
	            
	            if(this.getX() <= -this.getWidth()){
	          	  this.stopAnimation();
	          	  return false;
	            }
	            else return true;
			}
	}

	public int getCamara_height() {
		return camara_height;
	}

	public void setCamara_height(int camara_height) {
		this.camara_height = camara_height;
	}
}
